﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Taoyl.CodeTraceHelper;
using Taoyl.CodeTraceModels;
using xbd.DataConvertLib;

namespace Taoyl.CodeTraceBLL
{
    public class SysInfoManager
    {
        public static bool SaveSysInfo(SysInfo sysInfo, string path)
        {
            return IniConfigHelper.WriteIniData("系统配置", "配置信息", JsonHelper.SerializeObject(sysInfo), path);
        }

        public static OperateResult<SysInfo> LoadSysInfo(string path)
        {
            string info = IniConfigHelper.ReadIniData("系统配置", "配置信息", "", path);

            if (info.Length == 0)
            {
                return OperateResult.CreateFailResult<SysInfo>("读取配置文件信息为空");
            }
            else
            {
                var result = JsonHelper.DeserializeObject<SysInfo>(info);
                if (result != null)
                {
                    return OperateResult.CreateSuccessResult<SysInfo>(result);
                }
                else
                {
                    return OperateResult.CreateFailResult<SysInfo>("配置信息反序列化失败");
                }
            }
        }
    }
}
